package com.jy.app.lib.view.qrcode.zxing.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.MediaStore;

import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.EncodeHintType;
import com.google.zxing.Result;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeReader;
import com.jy.app.lib.view.qrcode.zxing.decoding.BitmapLuminanceSource;

import java.io.IOException;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;

public class Utils {
public static String distinguish(Context context,Uri uri){
	
	Bitmap bitmap = null;
	 try {
		bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), uri);
	} catch (IOException e) {
		e.printStackTrace();
	}
	Map<DecodeHintType, String> hints = new HashMap<>();
    hints.put(DecodeHintType.CHARACTER_SET, "utf-8");
    BitmapLuminanceSource source = new BitmapLuminanceSource(bitmap);
    BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));  
    QRCodeReader reader2= new QRCodeReader();
    Result result = null;
    try {
		result = reader2.decode(bitmap1,hints);
		return result.getText().toString();
	} catch (Exception e) {
		e.printStackTrace();
	}
    return null;
}


}
